<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;
use Encore\Admin\Form\Field;
use App\Models\Course;

class InsertScore
{
    protected $id;

    public function __construct($id,$row)
    {
        $course = Course::where('id',$row->course_id)->first();
        $total = $course->total;
        $this->id = $id;
        $this->total = $total;
    }

    protected function script()
    {
        return <<<SCRIPT

$('.grid-check-row').on('click', function () {
    var id=  $(this).data('id');
    var total = $(this).data('total');
    location.href = "/admin/tm/insert?id=" + id + '&total=' + total;
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "<a class='btn btn-xs fa fa-pencil-square-o grid-check-row' data-id='{$this->id}' data-total='{$this->total}' >&nbsp;&nbsp;成绩录入</a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}